package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.domain.Brand;
import com.spzx.product.mapper.BrandMapper;
import com.spzx.product.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 品牌Service业务层处理
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService  {



    @Override
    public int addBrand(Brand brand) {
        // 判断是否有重复品牌
        Brand brand1 = baseMapper.selectById(brand.getId());
        if (brand1 == null) {
            // 新增
            return baseMapper.insert(brand);
        }else {
            throw new ServiceException("品牌已存在");
        }

    }

    @Override
    public Page<Brand> getBrandList(Integer page, Integer size) {
        Page<Brand> brandPage = new Page<>(page, size);
        return baseMapper.getBrandList(brandPage);
    }
}
